#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>

using namespace std;

istream& f(istream& in)
{
  string v;
  while (in >> v, !in.eof())
  {
    if (in.bad())
    {
      throw runtime_error("IO stream failed!");
    }

    if (in.fail())
    {
      cerr << "data failed! Please try it again!\n";
      in.clear();
      in.ignore();
      continue;
    }
    cout << v << endl;
  }
  in.clear();
  return in;
}

int main(void)
{
  ostringstream msg;
  msg << "C++ Primer 5th" << endl;
  istringstream in(msg.str());
  f(in);

  return 0;
}


